package NewCoder;

import java.util.ArrayList;
import java.util.LinkedList;

public class BM45 {
    public ArrayList<Integer> maxInWindows(int [] num, int size) {
        LinkedList<Integer> list=new LinkedList<>();
        if(num.length==0) return new ArrayList<>(0);
        ArrayList<Integer> arr=new ArrayList<>();
        for(int i=0;i<num.length;i++) {
            while (!list.isEmpty() && num[list.peekLast()] < num[i]) {
                list.pollLast();
            }
            list.addLast(i);
            if (list.peek() <= i - size) {
                list.pollFirst();
            }
            if (i + 1 >= size) {
                arr.add(num[list.peekFirst()]);
            }
        }
        return arr;
    }
}
